package com.service.pay.diamond.mapper;

import com.service.pay.diamond.dto.OrderDto;
import com.service.pay.diamond.model.OrderModel;
import com.service.pay.diamond.model.UnifiedOrderModel;
import com.service.pay.diamond.tool.DmUtil;
import org.modelmapper.ModelMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class OrderMapper {
    @Autowired
    private ModelMapper mapper;
    @Autowired
    private DmUtil dmUtil;

    public OrderDto modelToDto(OrderModel orderModel) {
        if (null == orderModel) {
            return null;
        }
        return mapper.map(orderModel, OrderDto.class);
    }

    public OrderModel unifiedModelToOrderModel(UnifiedOrderModel prepareOrder, OrderModel order) {
        if (null == prepareOrder) {
            return null;
        }
        OrderModel orderModel = mapper.map(prepareOrder, OrderModel.class);
        orderModel.setTransactionId(dmUtil.generateTransactionId());
        orderModel.setId(order.getId());
        return orderModel;
    }
}
